package Resource;

import java.io.*;

public class TryCatchResource_01 {

    public static void main(String[] args) {

        try
        (
                //只能放资源对象，用完会自动关闭，自动调用对象的close方法关闭资源，即使出现异常操作也会关闭
                InputStream is = new FileInputStream("E:\\JavaSE\\src\\test1.txt");
                InputStream bis=new BufferedInputStream(is);
                OutputStream os= new FileOutputStream("E:\\JavaSE\\src\\test1.txt");
                Reader fr=new FileReader("");
        )
        {
            byte[] buffer = new byte[1024];
            int len;
            //将读出的字符装入buffer中 然后返回长度
            while((len=is.read(buffer))!=-1){
                os.write(buffer,0,len);
            }
            System.out.println("success");

            int code;
            while ((code=fr.read())!=-1){
            System.out.println((char) code);
        }

            char[] chars = new char[1024];
            int len2;
            while((len2=fr.read(chars))!=-1){
                String s = new String(buffer, 0, len2);
                System.out.println(s);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
